package com.wxzz.elearing.user.api.admin;


import com.alibaba.fastjson.JSONObject;
import com.wxzz.elearing.user.dto.AdminGuidelineDto;
import com.wxzz.elearing.user.dto.AdminNodeListDto;
import com.wxzz.elearing.user.dto.WorkNodeDto;
import com.wxzz.elearing.user.entity.AdminWorkGuideline;
import com.wxzz.elearing.user.entity.AdminWorkNode;
import com.wxzz.elearing.user.service.IAdminWorkNodeService;
import com.wxzz.elearing.user.vo.AdminWorkNodeVo;
import com.wxzz.elearning.common.vo.JgPageVo;
import com.wxzz.elearning.common.vo.ReturnVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 
 * @since 2021-05-16
 */
@RestController
@RequestMapping("/admin-work-node")
@Api(tags = "工作指引节点(后台)")
public class AdminWorkNodeController {

    @Autowired
    private IAdminWorkNodeService adminWorkNodeService;

    @Autowired
    private RedisTemplate<String,String> redisTemplate;

    @ApiOperation(value = "添加或修改工作指引节点", notes = "添加或修改工作指引节点", httpMethod = "POST", tags = "后台")
    @RequestMapping(value = "addAdminWorkNode", method = RequestMethod.POST)
    public ReturnVO addAdminWorkNode(@RequestHeader String token,  @RequestBody AdminWorkNode adminWorkNode) {
        JSONObject jsonObject = JSONObject.parseObject(redisTemplate.opsForValue().get(token));
        adminWorkNode.setEnterpriseId(jsonObject.getInteger("enterpriseId"));
        adminWorkNode.setAdminUserId(jsonObject.getLong("id"));
        return adminWorkNodeService.addAdminWorkNode(adminWorkNode);
    }


    @ApiOperation(value = "工作指引详情列表", notes = "工作指引详情列表", httpMethod = "POST", tags = "后台")
    @RequestMapping(value = "adminNodeList", method = RequestMethod.POST)
    public ReturnVO<JgPageVo<List<AdminWorkNodeVo>>> adminNodeList(@RequestHeader String token, @RequestBody AdminNodeListDto adminNodeListDto) {
        JSONObject jsonObject = JSONObject.parseObject(redisTemplate.opsForValue().get(token));
        adminNodeListDto.setEnterpriseId(jsonObject.getInteger("enterpriseId"));
        return adminWorkNodeService.getadminNodeList(adminNodeListDto);
    }

    @ApiOperation(value = "删除节点", notes = "删除节点", httpMethod = "POST", tags = "后台")
    @RequestMapping(value = "deleteWorkNode", method = RequestMethod.POST)
    public ReturnVO deleteWorkNode(@RequestHeader String token, @RequestBody WorkNodeDto workNodeDto) {
//        JSONObject jsonObject = JSONObject.parseObject(redisTemplate.opsForValue().get(token));
//        adminWorkGuideline.setCreatePerson(jsonObject.getLong("enterpriseId"));
//        adminWorkGuideline.setCreatePerson(jsonObject.getString("nickname"));
        return adminWorkNodeService.deleteWorkNode(workNodeDto);
    }
}
